package com.yzt.zhuju.network;

import com.yzt.zhuju.network.service.AccountService;
import com.yzt.zhuju.network.service.ChatRoomService;
import com.yzt.zhuju.network.service.DynamicService;
import com.yzt.zhuju.network.service.GiftService;
import com.yzt.zhuju.network.service.MainService;
import com.yzt.zhuju.network.service.MessageService;
import com.yzt.zhuju.network.service.MineService;
import com.yzt.zhuju.network.service.IndexService;
import com.yzt.zhuju.network.service.SystemService;
import com.yzt.plugin_network.BaseNetLayer;

/**
 * author : bob
 * date   : 2022/11/29
 * desc   :
 */
public class NetLayer extends BaseNetLayer {

    private static final NetLayer instance = new NetLayer();

    private MineService mMineService;
    private AccountService mAccountService;
    private MessageService mMessageService;
    private SystemService mSystemService;
    private IndexService mSayuService;
    private GiftService mGiftService;
    private MainService mMainService;
    private ChatRoomService mChatRoomService;
    private DynamicService mDynamicService;

    public static NetLayer getInstance() {
        return instance;
    }

    private NetLayer() {
        super();
        init();
    }

    private void init() {
        //设置ssl验证
       // mOKBuilder.sslSocketFactory(createSSLSocketFactory(), new MyX509TrustManager());
        mOKBuilder.addInterceptor(new HeadInterceptor());
        mRbuilder.baseUrl(HttpUrlManager.getAppHttpUrl());
    }

    public synchronized MineService getMineService() {
        if (mMineService == null) {
            mMineService = NetLayer.getInstance().build(MineService.class);
        }
        return mMineService;
    }

    public synchronized AccountService getAccountService() {
        if (mAccountService == null) {
            mAccountService = NetLayer.getInstance().build(AccountService.class);
        }
        return mAccountService;
    }

    public synchronized MessageService getMessageService() {
        if (mMessageService == null) {
            mMessageService = NetLayer.getInstance().build(MessageService.class);
        }
        return mMessageService;
    }

    public synchronized SystemService getSystemService() {
        if (mSystemService == null) {
            mSystemService = NetLayer.getInstance().build(SystemService.class);
        }
        return mSystemService;
    }

    public synchronized IndexService getIndexService() {
        if (mSayuService == null) {
            mSayuService = NetLayer.getInstance().build(IndexService.class);
        }
        return mSayuService;
    }

    public synchronized GiftService getGiftService() {
        if (mGiftService == null) {
            mGiftService = NetLayer.getInstance().build(GiftService.class);
        }
        return mGiftService;
    }

    public synchronized MainService getMainService() {
        if (mMainService == null) {
            mMainService = NetLayer.getInstance().build(MainService.class);
        }
        return mMainService;
    }

    public synchronized ChatRoomService getChatRoomService() {
        if (mChatRoomService == null) {
            mChatRoomService = NetLayer.getInstance().build(ChatRoomService.class);
        }
        return mChatRoomService;
    }


    public synchronized DynamicService getDynamicService() {
        if (mDynamicService == null) {
            mDynamicService = NetLayer.getInstance().build(DynamicService.class);
        }
        return mDynamicService;
    }

    public void changUrl() {
        reset();
        mMineService = null;
        mAccountService = null;
        mMessageService = null;
        mSystemService = null;
        mSayuService = null;
        mGiftService = null;
        mMainService = null;
        mChatRoomService = null;
        mDynamicService = null;
        init();
    }
}

